/**
 * 副本首领
 */
const Router = require('@koa/router');
const { JournalEncounter } = require('../db/schemas')

const { Language } = require('../env');
const { genResponse, raw$project } = require('../utils');

const router = new Router({ prefix: '/journal-encounter' })

router.get('/', async (ctx) => {
  const results = await JournalEncounter.aggregate([
    {
      $project: {
        _id: 0,
        id: 1,
        name: `$name.${Language}`,
        description: `$description.${Language}`,
        items: {
          $map: {
            input: '$items',
            as: 'i',
            in: {
              id: '$$i.item.id',
              name: `$$i.item.name.${Language}`
            }
          }
        },
        updated_at: 1,
        raw: '$$ROOT'
      }
    },
    raw$project,
  ])
  ctx.body = genResponse(true, results)
})
module.exports = router